package com.dhcc.core.modules.system.entity;

import com.baomidou.mybatisplus.annotations.TableName;
import com.dhcc.core.framework.base.entity.DataEntity;
import com.dhcc.core.framework.util.CommonUtil;


/**
 * 系统分表对象表
 * 
 * @ClassName: SplitTablesEntity
 * @Description: TODO
 * @author syj
 * @date 2022-03-14 14:04:56
 */
@TableName("sys_split_tables") 
public class SplitTablesEntity extends DataEntity<SplitTablesEntity> {
	private static final long serialVersionUID = 1L;

	//数据表名
	private String tableName;
	//数据表注释
	private String tableComment;
	//关联主表ID
	private Long parentId;
	//关联字段
	private String joinField;
	//层级
	private Integer levels;

	/**
	 * 设置：数据表名
	 */
	public void setTableName(String tableName) {
		this.tableName = tableName;
	}
	/**
	 * 获取：数据表名
	 */
	public String getTableName() {
		return tableName;
	}
	/**
	 * 设置：数据表注释
	 */
	public void setTableComment(String tableComment) {
		this.tableComment = tableComment;
	}
	/**
	 * 获取：数据表注释
	 */
	public String getTableComment() {
		return tableComment;
	}
	/**
	 * 设置：关联主表ID
	 */
	public void setParentId(Long parentId) {
		this.parentId = parentId;
	}
	/**
	 * 获取：关联主表ID
	 */
	public Long getParentId() {
		return parentId;
	}

	public String getJoinField() {
		return joinField;
	}

	public void setJoinField(String joinField) {
		this.joinField = joinField;
	}

	/**
	 * 设置：层级
	 */
	public void setLevels(Integer levels) {
		this.levels = levels;
	}
	/**
	 * 获取：层级
	 */
	public Integer getLevels() {
		return levels;
	}

	/**
	 * 根据请求的父级编号设置和层级
	 */
	public void init() {
		if (CommonUtil.isEmpty(this.getParentId())) {
			this.setLevels(1);
		} else {
			SplitTablesEntity parent =  this.selectById(this.getParentId());
			this.setParentId(parent.getId());
			this.setLevels(parent.getLevels()+1);
		}
	}
}
